<template>
  <div class="app-container">
    <el-row>
      <el-col :span="6" class="tl-left-tree">
        <!-- 树 -->
        <el-input v-model="queryTreeParam.qry_name" placeholder="请输入流程名称" @keyup.enter.native="filterTree" ref="treeSearch">
          <el-button current-node-key="" slot="append" icon="el-icon-search" @click="filterTree"></el-button>
        </el-input>
        <el-scrollbar ref="treeScroll" :style="{ height: treeHeight + 'px' }" resizable-key="treeHeight" :resizable-reduce="20" :resizable-refs="['treeSearch']">
          <el-tree class="tl-tree" ref="tree" :data="treeData" node-key="id" :default-expand-all="true" highlight-current :expand-on-click-node="false" @node-click="doTreeQuery" :filter-node-method="filterTreeNode"></el-tree>
        </el-scrollbar>
      </el-col>
      <el-col :span="18">
        <el-row>
          <!-- 查询 -->
          <tl-search ref="search" :query-param="queryParam" @search="doQuery" v-if="isHeaderDisplay"> </tl-search>
        </el-row>
        <el-card>
          <el-row ref="selector">
            <!-- 列表选择 -->
            <div class="table-alert-div">
              <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
                <template slot="title">
                  已选择&nbsp;<a style="font-weight: bold;">{{ selectedRowKeys.length }}</a
                  >项&nbsp;&nbsp;
                  <a style="font-weight: bold;margin-left: 24px" @click="doClearSelected">全部清空</a>
                </template>
              </el-alert>
            </div>
          </el-row>
          <el-row>
            <el-table ref="mainTable" class="tl-table" :height="tableHeight" resizable-key="tableHeight" :resizable-reduce="42" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" style="width: 100%;" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" row-key="id" border fit :row-class-name="doChangeRowClassName" :default-sort="{ prop: 'sourcetype', order: 'ascending' }">
              <el-table-column type="selection" width="55px"> </el-table-column>
              <el-table-column type="index" label="序号" width="55px"> </el-table-column>
              <el-table-column prop="maintitle" label="名称" sortable="custom" sort-by="maintitle"></el-table-column>
              <el-table-column prop="dispsubmituserid" label="提交人" sortable="custom" sort-by="submituserid"></el-table-column>
              <el-table-column prop="submitdate" label="组织" sortable="custom" :formatter="dateFormat" sort-by="submitdate"></el-table-column>
              <el-table-column prop="dispstate" label="状态" sortable="custom" sort-by="sortcode"></el-table-column>
              <el-table-column label="操作" width="300px" header-align="center" align="center" v-slot="slotProps" fixed="right">
                <el-button type="text" icon="el-icon-edit" @click="openEditDialog('editForm', slotProps.row.id)"> 编辑</el-button>
                <el-button type="text" icon="el-icon-share" @click="openApprovalNodeMgr('mgrForm', slotProps.row.id, slotProps.row.sourceid, slotProps.row.sourcetype, slotProps.row.maintitle)">审批节点管理</el-button>
              </el-table-column>
            </el-table>
          </el-row>
          <!-- 列表分页 -->
          <el-row class="pagebar" ref="pager">
            <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
          </el-row>
        </el-card>
      </el-col>
      <!-- 编辑界面 -->
      <tl-edit ref="editForm" @refresh="doRefresh"></tl-edit>
      <tl-approval-node-mgr ref="mgrForm" @refresh="doRefresh"></tl-approval-node-mgr>
    </el-row>
  </div>
</template>
<script>
/** mixins */
import { mixin_tree_list } from '@tapui/mixins/mixin_tree_list'
/** 子组件 */
import tlEdit from './edit'
import tlApprovalNodeMgr from './approvalNodeMgr'
import tlSearch from '@tapui/components/Tap/List/ListSearch'
import tlToolbar from '@tapui/components/Tap/List/ListToolBar'
import { TreeQueryMode } from '@tapui/const/tapConst'
export default {
  name: 'cboApprovalFlowIns',
  mixins: [mixin_tree_list],
  components: { tlEdit, tlApprovalNodeMgr, tlSearch, tlToolbar },
  data() {
    return {
      urlPrefix: '/cbo/approvalFlowIns/',
      url: {},
      treeQueryKey: 'qry_flowid',
      sorterInfo: { // 排序参数
        sidx: 'id',
        sord: 'desc'
      }

    }
  },
  methods: {
    // 打开新增对话框之后
    afterOpenAddDialog(editForm, rowData) {
      if (rowData) {
        this.$set(this.$refs[editForm].model, 'dispparentid', rowData.name)
        this.$set(this.$refs[editForm].model, 'parentid', rowData.id)
      } else {
        if (this.selectTreeNode && this.selectTreeNode.id > 0) {
          this.$set(this.$refs[editForm].model, 'dispparentid', this.selectTreeNode.name)
          this.$set(this.$refs[editForm].model, 'parentid', this.selectTreeNode.id)
        }
      }
    },
    // 加载列表之前
    beforeLoadData() {
      this.queryParam.qry_type = '1' // 流程查询
      return true
    },
    openApprovalNodeMgr(mgrForm, id, sourceId, sourceType, maintitle) {
      this.$refs[mgrForm].id = id
      this.$refs[mgrForm].sourceId = parseInt(sourceId)
      this.$refs[mgrForm].sourceType = sourceType
      this.$refs[mgrForm].maintitle = maintitle
      this.$refs[mgrForm].visible = true
    },
    doQuery() {
      this.treeQueryMode = TreeQueryMode.TreeDlick // 查询方式为双击查询
      this.loadList({ currentPage: 1 })
    }
  }
}
</script>
<style lang="scss" scoped></style>
